<html>
<head>
    <#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <!-- Bootstrap Core CSS -->
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/good.lzy.css" rel="stylesheet">
    <style>
        .form_datetime{ position: relative;}
        .form_datetime small{ position: absolute; top: 3px; left: 260px; white-space: nowrap;}
    </style>
</head>
<body>
<div id="page-wrapper">
    <div class="panel">
        <div class="panel-body">
            <form id="myForm" class="form-horizontal">
                <input type="hidden" name="realName" id="realName" value="${member.name}">
                <input type="hidden" name="loginName" id="loginName" value="${member.account}">
                <input type="hidden" name="password" id="password" value="${member.passWord}">
                <input type="hidden" name="phone" id="phone" value="${member.account}">
                <input type="hidden" name="sex" id="sex" value="${member.sex}">
                <input type="hidden" name="email" id="email" value="${member.email}">
                <input type="hidden" id="identity" name="identity" value=""/>
                <input type="hidden" name="cityCode" id="cityCode" value="">

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4"><font color="red">*</font> 身份：</span>
                    <div class="col-sm-9 col-xs-8">
                        <select class="form-control required" id="selIdentity" name="selIdentity"
                                onchange="changeIdentity(this.value)">
                            <option value="">请选择用户身份</option>
                            <c:forEach items="${identities!}" var="identity">
                                <option value="${identity.id!}" id="identityId" name="identityId">${identity.name!}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <%--<div class="form-group">--%>
                    <%--<span class="control-label col-sm-2 col-xs-4"><font color="red">*</font> 状态：</span>--%>
                    <%--<div id="wrap" class="col-sm-9 col-xs-8">--%>
                        <%--<label>--%>
                            <%--<input class="fixed" type="radio" class="form-control" size="30" name="state" id="state" value="0" <c:if test="${member.status=='0'}">checked="checked" </c:if> ><span style="margin-left: 10px">启用</span>--%>
                            <%--<input class="hid hid1" type="radio" class="form-control" size="30" name="state" value="1" style="margin-left: 30px" <c:if test="${member.status=='1'}">checked="checked" </c:if> ><span style="margin-left: 10px">禁用</span>--%>
                        <%--</label>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4">合同编号：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="30" name="contractNumber" id="contractNumber" value="" maxlength="20">
                    </div>
                </div>
                <%--<div class="form-group">--%>
                    <%--<span class="control-label col-sm-2 col-xs-4">开始日期：</span>--%>
                    <%--<div id="start_time" class="col-sm-9 col-xs-8 input-group date form_datetime" style="width: 255px">--%>
                        <%--<input id="startTime" name="startTime" class="form-control" size="16" type="text" value="" style="margin-left: 15px" readonly>--%>
                        <%--<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>--%>
                        <%--<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<span class="control-label col-sm-2 col-xs-4">截止日期：</span>--%>
                    <%--<div id="end_time" class="col-sm-9 col-xs-8 input-group date form_datetime" style="width: 255px">--%>
                        <%--<input id="endTime" name="endTime" class="form-control" size="16" type="text" value="" style="margin-left: 15px" readonly>--%>
                        <%--<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>--%>
                        <%--<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group">--%>
                    <%--<span class="control-label col-sm-2 col-xs-4">盐值：</span>--%>
                    <%--<div class="col-sm-9 col-xs-8">--%>
                        <%--<input type="text" class="form-control" size="30" name="salt" id="salt" value="" maxlength="10">--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4">备注：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="30" name="remark" id="remark" value="" maxlength="20">
                    </div>
                </div>

                <div id="serviceArea" class="form-group" style="display: none">
                    <div class="control-label col-sm-2 col-xs-4"><font color="red">*</font><span class="area-tit">地址</span>：</div>
                    <div class="col-sm-9 col-xs-8">
                        <#include "../common/selectCity.ftl">
                            <#assign name="proviceVale" value="" />
                            <#assign name="provinceName" value="proId" />
                            <#assign name="cityName" value="cityId" />
                            <#assign name="areaName" value="disId" />
                            <#assign name="selp" value="selprovince" />
                            <#assign name="selc" value="selcity" />
                            <#assign name="sela" value="selarea" />
                    </div>
                </div>

                <%--<div id="agentArea" class="form-group" style="display: none">--%>
                    <%--<span class="control-label col-sm-2 col-xs-4"><font color="red">*</font>代理地区：</span>--%>
                    <%--<div class="col-sm-9 col-xs-8">--%>
                        <%--<#assigninclude page="../common/selectCity.jsp">--%>
                            <%--<#assignparam name="proviceVale" value="" />--%>
                            <%--<#assignparam name="provinceName" value="proId" />--%>
                            <%--<#assignparam name="cityName" value="cityId" />--%>
                            <%--<#assignparam name="areaName" value="disId" />--%>
                            <%--<#assignparam name="selp" value="selprovince" />--%>
                            <%--<#assignparam name="selc" value="selcity" />--%>
                            <%--<#assignparam name="sela" value="selarea" />--%>
                        <%--</#assigninclude>--%>
                    <%--</div>--%>
                <%--</div>--%>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4"></span>
                    <div class="col-sm-9 col-xs-8">
                        <button type="button" class="btn btn-success" onclick="submitForm();"><i class="fa fa-check"></i> 确定</button>
                        <button type="button" class="btn btn-info" onclick="closePage();"><i class="fa fa-close"></i> 关闭</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="good-add-suc">
    <span>
        <b>操作成功</b>
        该页面将在 5 秒后自动跳转！
        <a href="${basePath}/admin/member" target="_parent">返回列表</a>
    </span>
</div>

<script src="${basePath}/bootstrap/js/jquery.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- js验证提示 -->
<!-- layer JavaScript -->
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<!-- bootstrap-datetimepicker -->
<script type="text/javascript" src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>');
</script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/language/zh_CN.js"></script>
<script>
    var action="${action}";
    // 初始化
    $(function () {
        //时间控件注册
        $('#start_time').datetimepicker({
            minView: "month", //选择日期后，不会再跳转去选择时分秒
            format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
            language: 'zh-CN', //汉化
            autoclose:true //选择日期后自动关闭
        });
        //时间控件注册
        $('#end_time').datetimepicker({
            minView: "month", //选择日期后，不会再跳转去选择时分秒
            format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
            language: 'zh-CN', //汉化
            autoclose:true //选择日期后自动关闭
        });

        //服务商
        $("#selIdentity").change(function(){
            var serviceArea = $("#serviceArea");
            var tit = $(".area-tit");
            if($(this).val() == 1){
                tit.html("地址");
                serviceArea.show();
            }
            else if($(this).val() == 2){
                tit.html("代理地区");
                serviceArea.show();
            }
            else{
                serviceArea.hide();
            }
        })

//        //代理商
//        $("#selIdentity").change(function(){
//            var agentArea = $("#agentArea");
//            if($(this).val() == 2){
//                agentArea.show();
//            }
//            else{
//                agentArea.hide();
//            }
//        })

    });

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //关闭窗口并刷新页面
    function closePage() {
        parent.layer.close(index);
    }
    var codeVal;
    function submitForm() {
        codeVal = $("#selarea").val() || $("#selcity").val() || $("#selprovince").val();
        var bsVal = $("#myForm").data('bootstrapValidator');
        bsVal.validate();
        if(bsVal.isValid()) {

            $.ajax({
                url: '${basePath}/admin/manager/' + action,
                dataType: 'json',
                type: 'POST',
                data: {
                    cityCode: codeVal,
                    realName: $('#realName').val(),
                    loginName: $('#phone').val(),
                    password: $('#password').val(),
                    phone: $('#phone').val(),
                    sex: $('#sex').val(),
                    identityId: $('#identity').val(),
                    email: $('#email').val(),
                    state: $('#wrap input[name="state"]:checked ').val(),
                    contractNumber: $('#contractNumber').val(),
                    startTime: $('#startTime').val(),
                    endTime: $('#endTime').val(),
                    salt: $('#salt').val(),
                    remark: $('#remark').val()
                },
                success: function (data) {
                    if (data.code == '0000' || data.code == '0') {
                        layer.open({
                            type: 1,
                            title: false,
                            content: $(".good-add-suc"),
                            area: ['600px', '300px'],
                            time: 5000,
                            end: function () {
                                parent.layer.closeAll();
                                window.location.href = '${basePath}/admin/member';
                            }
                        });
                    } else {
                        layer.alert(data.desc, {
                            icon: 56
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });
        }
    }

    function changeIdentity(value) {
        $("#identity").val(value);
    }
    $('#myForm').bootstrapValidator({
        excluded: [":disabled"],
        fields: {
            selIdentity: {
                validators: {
                    notEmpty: {
                        message: '请选择身份'
                    }
                }
            }
//            ,
//            state: {
//                validators: {
//                    notEmpty: {
//                        message: '请选择状态'
//                    }
//                }
//            },
//            contractNumber: {
//                validators: {
//                    notEmpty: {
//                        message: '请输入合同编号'
//                    }
//                }
//            }
//            ,
//            startTime: {
//                trigger:"change focus blur",
//                validators: {
//                    notEmpty: {
//                        message: '请选择开始日期'
//                    }
//                }
//            },
//            endTime: {
//                trigger:"change focus blur",
//                validators: {
//                    notEmpty: {
//                        message: '请选择截止日期'
//                    }
//                }
//            }
        }
    })
</script>
</body>
</html>
